const mixins = require('../../mixins/user')
const forums = require('../../mixins/forum');
const common = require('../../mixins/common');
import config from "../../api/config";
var app = getApp();
const options = {

  /**
   * 页面的初始数据
   */
  data: {
    followlist: [],
    page: 1,
    isLastPage: false,
    isNull:false,
    iconTheme:'white',
    currentConfig: config.currentConfig,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      id: options.id
    })
    if (options.id == 0) {
      this.setData({
        isNull: true
      })
    } else {
      this.getUserinfoById(options.id);
      this.getUserArticle({
        author:options.id,
        page: this.data.page,
        custom:'anonymity'});
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let user = app.globalData.user
    if (!user) {
      user = '';
    }
    this.setData({
      user: user,
    })
  },


  /**
   * 取消
   */
  onClickCancle: function () {
    this.setData({
      showDialog: !this.data.showDialog
    })

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 显示删除菜单
   */

  editOrDeleteTap: function () {
    this.setData({
      showDialog: !this.data.showDialog,
      bounced: !this.data.bounced
    })
  },

  gotoDetail: function (e) {
    console.log(e);
    let id = e.currentTarget.id;
    wx.navigateTo({
      url: '/pages/detail/detail?id=' + id + '&type=forums',
    })
  },


  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      posts:[],
      isLastPage:false,
      page: 1,
    })
    this.getUserArticle({
      author:this.data.id, 
      page:this.data.page,
      custom:'anonymity'
     });
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.setData({
      isBottom: true,
    })
    if (!this.data.isLastPage) {
      this.getUserArticle({
       author:this.data.id, 
       page:this.data.page,
       custom:'anonymity'
      });
    }
  },

  
  onPageScroll: function onPageScroll(e) {
    var that = this;
    var trans = (e.scrollTop > 55 ? 55 : e.scrollTop) / 55;
    var frontColor = "#ffffff";
    var backgroundColor = "#000000";
    var iconTheme = "white";
    if (trans == 0) {
        frontColor = "#ffffff";
        backgroundColor = "#000000";
        iconTheme = "white";
    } else if (trans >= .4) {
        frontColor = "#000000";
        backgroundColor = "#ffffff";
        iconTheme = "black";
    }
    that.setData({
        navbarTrans: trans,
        iconTheme: iconTheme
    });
    wx.setNavigationBarColor({
        frontColor: frontColor,
        backgroundColor: frontColor,
        animation: {
            duration: 400,
            timingFunc: "easeIn"
        }
    });
    
    that.data.scrollTop = e.scrollTop;
},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
}


mixins(options)
forums(options)
common(options)
Page(options)